<template>
  <el-form
    ref="userForm"
    :model="userInfo"
    label-width="120px"
    style="margin-left: 120px; margin-top: 30px"
  >
    <el-form-item label="姓名:">
      <el-input v-model="userInfo.username" style="width: 300px" />
    </el-form-item>
    <el-form-item label="密码:" >
      <el-input
        v-model="userInfo.password"
        type="password"
        style="width: 300px"
        disabled
      />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="loadDepartments">更新</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { headPortraits } from "@/api/user";
import { Departments } from "@/api/departments";
export default {
    props:{

        id: {
          type: String,
          required: true,
        }
    },
  data() {
    return {
      userInfo: {
        username: "",
        password: "",
      },
    };
  },
  created() {
    this.loadPortraits();
  },
  methods: {
    // 获取员工数据
    async loadPortraits() {
      try {
        const res = await headPortraits(this.id);
        // console.log(res);
        this.userInfo = res.data;
      } catch (error) {
        console.log(error);
      }
    },
    // 添加员工数据
    async loadDepartments(){
        try {
            const res =await Departments(this.userInfo)
            this.loadPortraits()
            this.$router.back()
        } catch (error) {
           console.log(error); 
        }
    }
  },
};
</script>